Skip to content

fix(frontend): prevent session polling from stopping permanently after backend errors#1692

Merged
markturansky merged 2 commits into
ambient-code:mainfrom
markturansky:fix/session-polling-stuck-on-error
Jun 15, 2026
Merged

fix(frontend): prevent session polling from stopping permanently after backend errors#1692
markturansky merged 2 commits into
ambient-code:mainfrom
markturansky:fix/session-polling-stuck-on-error

Conversation

@markturansky

@markturansky markturansky commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • When the backend restarts during session creation, useSession's refetchInterval callback receives undefined data (query in error state after retries exhausted). The phase-based polling logic falls through to return false, permanently stopping polling — the UI gets stuck on "Starting Session" forever.
  • Adds if (\!session) return 2000; early return to keep polling every 2s when data is unavailable, allowing automatic recovery once the backend is reachable.

Root Cause

refetchInterval reads query.state.data which is undefined when the query is in error state. The existing logic only checked phase values (Running, Pending, etc.), so when phase was undefined, the function fell through to return false — permanently disabling polling.

Evidence

Backend logs showed ZERO session detail requests after the initial failures — only pod-events requests were reaching the backend. The SessionStartingEvents component polls pod-events unconditionally (not gated by React Query's refetchInterval), which is why those continued while useSession polling stopped.

Test plan

  • TypeScript check passes (npx tsc --noEmit)
  • Next.js build passes (npm run build)
  • Verify on UAT: create a new session while backend is restarting, confirm UI recovers to chat view after backend comes back

🤖 Generated with Claude Code

Summary by CodeRabbit

Bug Fixes

  • Improved session data loading performance by preventing unnecessary computations while session information is still being retrieved.

…r backend errors

When the backend restarts during session creation, useSession's refetchInterval
callback receives undefined data (query in error state). Without an early return,
the phase-based logic falls through to `return false`, permanently stopping polling.
The session UI gets stuck on "Starting Session" and never recovers.

Add early return `if (\!session) return 2000` to keep polling every 2s when data is
unavailable, allowing the UI to recover once the backend is reachable again.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@netlify

netlify Bot commented Jun 15, 2026

Copy link
Copy Markdown

Deploy Preview for cheerful-kitten-f556a0 ready!

Name Link
🔨 Latest commit f8d137d
🔍 Latest deploy log https://app.netlify.com/projects/cheerful-kitten-f556a0/deploys/6a307c1f7f4107000891590a
😎 Deploy Preview https://deploy-preview-1692--cheerful-kitten-f556a0.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 927da718-83b0-43b9-8f63-50cb1185c827

📥 Commits

Reviewing files that changed from the base of the PR and between cbb6023 and 06b63a5.

📒 Files selected for processing (1)
  • components/frontend/src/services/queries/use-sessions.ts

📝 Walkthrough

Walkthrough

Adds a two-line early return in useSession's refetchInterval callback: if session data is undefined, it returns 2000 immediately, skipping phase and annotation computations that would otherwise run against an unloaded value.

Changes

Session undefined guard

Layer / File(s) Summary
Early return for undefined session
components/frontend/src/services/queries/use-sessions.ts
refetchInterval returns 2000 when !session, preventing phase/annotation logic from executing before data loads.
🚥 Pre-merge checks | ✅ 7 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (7 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title follows Conventional Commits format (fix(frontend):) and accurately describes the main change: preventing permanent polling stoppage when backend errors occur.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Performance And Algorithmic Complexity ✅ Passed No performance regression: Early guard clause in refetchInterval prevents unnecessary object access/phase checks when session is undefined. O(1) operation; no N+1, unbounded growth, or expensive wo...
Security And Secret Handling ✅ Passed Frontend polling fix adds defensive null check without introducing secrets, auth bypass, injection, or data leakage issues. No security violations detected.
Kubernetes Resource Safety ✅ Passed PR contains only TypeScript frontend code (useSession hook fix). Kubernetes Resource Safety check is not applicable as no Kubernetes manifests, RBAC, containers, or infrastructure definitions are p...

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Comment @coderabbitai help to get the list of available commands and usage tips.

@markturansky markturansky merged commit 0b0a1d9 into ambient-code:main Jun 15, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant